<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8" />
    <title>单一状态树</title>
    <script src="vue.js"></script>
    <script src="vuex.js"></script>
  </head>
  <body>
    <div id="app">
      <input type="button" value="单击增加1" @click="increment()" />
      {{ outputCount }}
    </div>
    <script>
      const store = new Vuex.Store({
        state: {
          count: 0,
        },
        mutations: {
          increment: (state) => state.count++,
        },
      });
      var vm = new Vue({
        el: "#app",
        computed: {
          outputCount() {
            return store.state.count;
          },
        },
        methods: {
          increment() {
            store.commit("increment");
            console.log(store.state.count);
          },
        },
      });
    </script>
  </body>
</html>
